package aom.ju.ss.view.user.shop.management.order

import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.ViewPager
import aom.ju.ss.R
import aom.ju.ss.databinding.OrderManageBinding
import aom.ju.ss.utils.data
import aom.ju.ss.utils.show
import aom.ju.ss.view.base.BaseActivity
import aom.ju.ss.view.base.TopBar

class OrderManage : BaseActivity() {
    private lateinit var binding: OrderManageBinding
    var fs = arrayListOf<Fragment>()
    override fun init() {

        binding = viewBinding as OrderManageBinding
        // 0 订单 1 售后

        if (data == "3") {
            binding.vp.currentItem = 2
        }
        fs.add(OrderListFragment.getMy("0",data))
        fs.add(OrderListFragment.getMy("1"))
        binding.vp.adapter = object : FragmentPagerAdapter(supportFragmentManager, 1) {
            override fun getCount(): Int {
                return 2
            }

            override fun getItem(position: Int): Fragment {
                return fs[position]
            }

        }

        binding.rootView.setPadding(0, TopBar.getStatusBarHeight(activity!!), 0, 0)
        binding.back.setOnClickListener { finish() }
        binding.order.setOnClickListener {
            binding.order.setBackgroundResource(R.drawable.bg_click_blue_4dp)
            binding.order.setTextColor(ContextCompat.getColor(activity!!, R.color.white))
            binding.shouhou.setBackgroundResource(R.drawable.bg_click_white_4dp)
            binding.shouhou.setTextColor(ContextCompat.getColor(activity!!, R.color.c646464))
            binding.vp.currentItem = 0
        }
        binding.shouhou.setOnClickListener {
            binding.order.setBackgroundResource(R.drawable.bg_click_white_4dp)
            binding.order.setTextColor(ContextCompat.getColor(activity!!, R.color.c646464))
            binding.shouhou.setBackgroundResource(R.drawable.bg_click_blue_4dp)
            binding.shouhou.setTextColor(ContextCompat.getColor(activity!!, R.color.white))
            binding.vp.currentItem = 1
        }


        binding.vp.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {

            }

            override fun onPageSelected(position: Int) {
                if (position == 0) {
                    binding.order.performClick()
                } else {
                    binding.shouhou.performClick()
                    "售后功能正在开发中..".show
                }
            }

            override fun onPageScrollStateChanged(state: Int) {
            }

        })
    }

    override val lay: Int = R.layout.order_manage

}